# Copyright 2020 Makani Technologies LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Automatically generated hover controllers.

This file was generated by:
  analysis/control/generate_hover_controllers.m
"""

from makani.control import control_types as m


def GetHoverControllers(wing_serial):
  """Returns the hover controller gains."""
  if wing_serial == m.kWingSerialOktoberKite01:
    low_altitude = {
        'kp': 1.94e+03,
        'ki': 137.,
        'kd': 6.84e+03
    }
    high_altitude = {
        'kp': 747.,
        'ki': 44.1,
        'kd': 3.16e+03
    }
    transform_tether_elevation = {
        'kp': 0.00,
        'ki': -16.0,
        'kd': 0.00
    }
    reel_tether_elevation = {
        'kp': 0.00,
        'ki': 0.0375,
        'kd': 0.00
    }
    roll = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': 0.00
    }
    low_thrust_pitch = {
        'kp': 5.06e+04,
        'ki': 2.14e+03,
        'kd': 4.12e+04
    }
    pitch = {
        'kp': 1.05e+05,
        'ki': 6.64e+03,
        'kd': 6.20e+04
    }
    yaw = {
        'kp': 3.77e+05,
        'ki': 2.98e+04,
        'kd': 1.91e+05
    }
    tangential_short_tether = {
        'kp': 0.0100,
        'ki': 0.000144,
        'kd': 0.0757
    }
    tangential_low_altitude_long_tether = {
        'kp': 0.0408,
        'ki': 0.00147,
        'kd': 0.168
    }
    tangential_high_altitude_long_tether = {
        'kp': 0.00621,
        'ki': 3.97e-05,
        'kd': 0.0288
    }
    radial = {
        'kp': 0.00,
        'ki': 0.00,
        'kd': -0.0511
    }
    tension_hard = {
        'kp': 0.00,
        'ki': 1.00e-05,
        'kd': 0.00
    }
    tension_soft = {
        'kp': 0.00,
        'ki': 1.00e-06,
        'kd': 0.00
    }
    int_pitch = {
        'kp': 7.86e+04,
        'ki': 1.04e+03,
        'kd': 0.00
    }
    int_yaw = {
        'kp': 5.12e+04,
        'ki': 1.02e+04,
        'kd': 0.00
    }
  else:
    assert False, 'wing_serial %d was not recognized' % wing_serial

  return {
      'low_altitude': low_altitude,
      'high_altitude': high_altitude,
      'transform_tether_elevation': transform_tether_elevation,
      'reel_tether_elevation': reel_tether_elevation,
      'roll': roll,
      'low_thrust_pitch': low_thrust_pitch,
      'pitch': pitch,
      'yaw': yaw,
      'tangential_short_tether': tangential_short_tether,
      'tangential_low_altitude_long_tether': (
          tangential_low_altitude_long_tether),
      'tangential_high_altitude_long_tether': (
          tangential_high_altitude_long_tether),
      'radial': radial,
      'tension_hard': tension_hard,
      'tension_soft': tension_soft,
      'int_pitch': int_pitch,
      'int_yaw': int_yaw,
  }
